﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core;

namespace Baosight.ZNH.ZM.UI
{
    /// <summary>
    /// 首页材料需求和领料申请
    /// </summary>
    /// Title:ZM98
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 张志芳
    /// Version: 1.0
    /// History:
    ///       2012-12-20  张志芳   [创建]
    ///  
    public partial class ZM98 : EFViewCmes
    {
        public ZM98()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="initData"></param>
        public override void Initialize(Baosight.Platform.Core.EIInfo initData)
        {
            foreach (EIRow row in initData.GetBlock("planResult").Rows)
            {
                if (row["item"].Equals("已上报"))
                {
                    noAppValue.Text = row["value"] as string;
                }
                else if (row["item"].Equals("已审批"))
                {
                    noAuditValue.Text = row["value"] as string;
                }
            }
            foreach (EIRow row in initData.GetBlock("appResult").Rows)
            {
                if (row["item"].Equals("上报"))
                {
                    ReportNum.Text = row["value"] as string;
                    break;
                }               
            }

            this.PlanPieChart.ItemsSource = initData.GetBlock("planResult").Rows;
            this.AppPieChart.ItemsSource = initData.GetBlock("appResult").Rows;
        }

        /// <summary>
        /// 材料计划未审批——链接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            link.IsEnabled = false;
            if (noAppValue.Text.Equals("0"))
            {
                BaseTools.OpenEFWindowAlert("没有要处理的数据！", null);
                link.IsEnabled = true;
                return;
            }
            Shell.LoadView("ZMCM23");
            link.IsEnabled = true;
        }

        /// <summary>
        /// 材料计划未审核——链接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click_1(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            link.IsEnabled = false;
            if (noAuditValue.Text.Equals("0"))
            {
                BaseTools.OpenEFWindowAlert("没有要处理的数据！", null);
                link.IsEnabled = true;
                return;
            }
            Shell.LoadView("ZMCM26");
            link.IsEnabled = true;
        }

        /// <summary>
        /// 领料申请未审批——链接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click_2(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            link.IsEnabled = false;
            if (ReportNum.Text.Equals("0"))
            {
                BaseTools.OpenEFWindowAlert("没有要处理的数据！", null);
                link.IsEnabled = true;
                return;
            }
            Shell.LoadView("ZMCM83");
            link.IsEnabled = true;
        }

    }
}
